<?php
namespace core\lib;
use \core\lib;
/**
* route
*/
class route
{
	public $ctrl;
	public $action;
	public function __construct()
	{
		//1.隐藏index.php
		//2.获取URL参数部分
		//3.返回对应控制器和方法
		//p($_SERVER);
		if (isset($_SERVER['REQUEST_URI']) && $_SERVER['REQUEST_URI'] != '/myframework/') {
			$path = $_SERVER['REQUEST_URI'];
			$patharr = explode('/', trim($path, '/'));
			unset($patharr[0]);
			if (isset($patharr[1])) {
				$this->ctrl = $patharr[1];
				unset($patharr[1]);
			}
			if (isset($patharr[2])) {
				$this->action = $patharr[2];
				unset($patharr[2]);
			} else {
				$this->action = config::get('route', 'ACTION');
			}
			$count = count($patharr) + 3;
			$i = 3;
			while ($i < $count) {
				if (isset($patharr[$i + 1])) {
					$_GET[$patharr[$i]] = $patharr[$i + 1];
				}
				$i += 2;
			}
			//p($_GET);
		} else {
			$this->ctrl = config::get('route', 'CTRL');
			$this->action = config::get('route', 'ACTION');
		}
	}
}